package com.course.domain.service.impl;

import com.course.domain.dao.AgendaInfoDao;
import com.course.domain.dao.AgendaWeekDao;
import com.course.domain.model.AgendaInfo;
import com.course.domain.model.AgendaWeek;
import com.course.domain.service.AgendaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Justin on 2017/5/12.
 */
@Service
public class AgendaServiceImpl implements AgendaService {

    private final AgendaInfoDao infoDao;
    private final AgendaWeekDao weekDao;

    @Autowired
    public AgendaServiceImpl(AgendaInfoDao infoDao,
                             AgendaWeekDao weekDao) {
        this.infoDao = infoDao;
        this.weekDao = weekDao;
    }

    @Override
    public AgendaInfo saveInfo(AgendaInfo info) {
        return infoDao.save(info);
    }

    @Override
    public AgendaInfo createInfo(AgendaInfo info) {
        return infoDao.save(info);
    }

    @Override
    public AgendaInfo updateInfo(AgendaInfo info) {
        return infoDao.save(info);
    }

    @Override
    public AgendaWeek saveWeek(AgendaWeek week) {
        return weekDao.save(week);
    }

    @Override
    public AgendaWeek createWeek(AgendaWeek week) {
        return weekDao.save(week);
    }

    @Override
    public AgendaWeek updateWeek(AgendaWeek week) {
        return weekDao.save(week);
    }

    @Override
    public AgendaInfo loadInfo(int agendaId) {
        return infoDao.findOne(agendaId);
    }

    @Override
    public AgendaInfo loadInfo(int studentId, int courseId) {
        return infoDao.findByStudentIdAndCourseId(studentId, courseId);
    }

    @Override
    public List<AgendaInfo> findInfo(List<Integer> agendaIds) {
        return infoDao.findAll(agendaIds);
    }

    @Override
    public List<AgendaWeek> findWeek(int agendaId) {
        return weekDao.findByAgendaIdOrderByPartIdx(agendaId);
    }
}
